<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Qualification extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->template->set_partial('header_search', 'header/header_search');
		$this->template->set_partial('nav_bar', 'header/nav_bar');
		$this->load->model('member/member_model');
		$this->load->model('member/profile_model');
		$this->load->model('member/qualification_model');
		
		
	}
	
	function index(){
	
		$data['mode'] = "ADD";
		/*GET PROFILE ID*/
		$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
		
		
		//var_dump($isProfile);
		//die();
		
		if($isProfile){
			$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			$data['profile_id'] = $profile_id;
			$data['profile']['info'] = $isProfile;
			$data['qualification']['details'] = $this->qualification_model->getQualification($profile_id);
		}else{
			$data['profile']['info'] = null;
		}
		/*GET PROFILE ID*/
		
		 	
		
		$this->template->set_layout('full_layout');
		$data['module_banner'] = FALSE;
		$data['module_recent_listing'] = TRUE;
		$data['module_news'] = FALSE;
		
		if($this->member_model->getMember($this->session->userdata['mem_id'])){
			$data['member']['info'] = $this->member_model->getMember($this->session->userdata['mem_id']);
		}
		
		$this->template->build('qualification',$data);
	}
	
	function edit($id)
	{
		$data['mode'] = "EDIT";
		
		/*GET PROFILE ID*/
		$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
		
		if($isProfile){
			$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			$data['profile_id'] = $profile_id;
			$data['profile']['info'] = $isProfile;
			}else{
			$data['profile_id'] = null;
		}
		/*GET PROFILE ID*/
		
		$data['qualification']['info'] = $this->qualification_model->getQualificationinof($id);
		
		$this->template->set_layout('full_layout');
		$data['module_banner'] = FALSE;
		$data['module_recent_listing'] = TRUE;
		$data['module_news'] = FALSE;
		
		if($this->member_model->getMember($this->session->userdata['mem_id'])){
			$data['member']['info'] = $this->member_model->getMember($this->session->userdata['mem_id']);
		}
		
		$this->template->build('qualification',$data);
		
	}
	
	function submit_qualification()
	{
		
		/*GET PROFILE ID*/
		$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
		
		if($isProfile){
			$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			$data['profile_id'] = $profile_id;
			$data['profile']['info'] = $isProfile;
			//$data['qualification']['deatils'] = $this->member_model->getQualification($profile_id);
		}else{
			$data['profile_id'] = null;
		}
		
		$this->form_validation->set_rules('institute', 'Institute/College', 'required|xss_clean');
		$this->form_validation->set_rules('major_subject', 'Major Subject', 'required|xss_clean ');
		$this->form_validation->set_rules('year', 'Year', 'required|xss_clean');
	
		if ($this->form_validation->run() == true) {
	
	
			$profile_id = $profile_id;
	
			$post_data=array(
	
					'profile_id' => $profile_id,
					'institute' => $this->input->post('institute'),
					'subject' => $this->input->post('major_subject'),
					'year' => $this->input->post('year'),
	
			);
	
			$this->db->insert('qualification',$post_data);
			$this->session->set_flashdata('message', 'Sucessfully!... ');
			redirect('member/qualification');
	
		} else {
			$this->session->set_flashdata('message', 'Invalid');
			$this->index();
			
			//redirect('member/qualification');
		}
	}
	
	function update_qualification()
	{
	/*GET PROFILE ID*/
		$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
		
		if($isProfile){
			$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			$data['profile_id'] = $profile_id;
			$data['profile']['info'] = $isProfile;
		}else{
			$data['profile_id'] = null;
		}
		
		$this->form_validation->set_rules('institute', 'Institute/College', 'required|xss_clean');
		$this->form_validation->set_rules('major_subject', 'Major Subject', 'required|xss_clean ');
		$this->form_validation->set_rules('year', 'Year', 'required|xss_clean');
	
		if ($this->form_validation->run() == true) {
	
			$id = $this->input->post('id');
			
			$post_data=array(
	
					//'profile_id' =>$profile_id,
					'institute' => $this->input->post('institute'),
					'subject' => $this->input->post('major_subject'),
					'year' => $this->input->post('year'),
	
			);
	
			$this->db->where('id',$id);
			$this->db->update('qualification',$post_data);
			$this->session->set_flashdata('message', 'Update Sucessfully!... ');
			redirect('member/qualification/edit/'.$id);
	
		} else {
			$this->session->set_flashdata('message', 'Invalid');
			redirect('member/qualification/edit/'.$id);
		}
	}
	
	
	function delete($id)
	{
		$this->qualification_model->deleteQualification($id);
		redirect('member/qualification');
	}
}